ProgressBarDelegate
Base classes
⋔ Inheritance diagram
graph TD
819939735["itemdelegates.ProgressBarDelegate"]
4109708588["widgets.StyledItemDelegate"]
3153451512["widgets.AbstractItemDelegateMixin"]
3227531497["core.ObjectMixin"]
2751680898["builtins.object"]
3599391368["QtWidgets.QStyledItemDelegate"]
475576970["QtWidgets.QAbstractItemDelegate"]
3984060476["QtCore.QObject"]
37984305["Shiboken.Object"]
4109708588 --> 819939735
3153451512 --> 4109708588
3227531497 --> 3153451512
2751680898 --> 3227531497
2751680898 --> 3153451512
3599391368 --> 4109708588
475576970 --> 3599391368
3984060476 --> 475576970
37984305 --> 3984060476
2751680898 --> 37984305
🛈 DocStrings
Bases: StyledItemDelegate
Delegate to show a value in form of a progress bar.
Source code in prettyqt/itemdelegates/progressbardelegate.py
| class ProgressBarDelegate(widgets.StyledItemDelegate):
"""Delegate to show a value in form of a progress bar."""
ID = "progress_bar"
def __init__(
self,
role: constants.ItemDataRole = constants.DISPLAY_ROLE,
total: int = 100,
**kwargs,
):
self._role = role
self._total = total
super().__init__(**kwargs)
def paint(
self,
painter: gui.QPainter,
option: widgets.QStyleOptionViewItem,
index: core.ModelIndex,
):
progress = index.data(self._role)
if progress is None:
return
opt = widgets.StyleOptionProgressBar()
opt.rect = option.rect
opt.minimum = 0
opt.maximum = self._total
opt.progress = int(progress)
pct = round(progress * 100 / self._total) if self._total else 0
opt.text = f"{pct}%"
opt.textVisible = True
opt.state |= widgets.Style.StateFlag.State_Horizontal
widgets.Application.style().drawControl(
widgets.Style.ControlElement.CE_ProgressBar, opt, painter
)
def set_total(self, total: int):
self._total = total
def get_total(self) -> int:
return self._total
def set_role(self, role: constants.ItemDataRole):
self._role = role
def get_role(self) -> constants.ItemDataRole:
return self._role
total = core.Property(
int,
get_total,
set_total,
doc="Total value for the progress bar",
)
role = core.Property(
constants.ItemDataRole,
get_role,
set_role,
doc="Role to use for the progress bar value",
)
|
:fa-brands-github: Show source on GitHub